package com.example.relevandopeligros;

import com.example.relevandopeligros.R;
import com.example.relevandopeligros.R.id;
import com.example.relevandopeligros.R.layout;
import com.example.relevandopeligros.R.menu;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;



public class MainActivity extends ActionBarActivity {
	/*It's generally a good practice to define keys for intent extras using 
	 * your app's package name as a prefix. This ensures they are unique, 
	 * in case your app interacts with other apps. */
    public final static String EXTRA_MESSAGE = "com.example.relevandopeligros.MESSAGE";
    
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }

	@Override
	public boolean onCreateOptionsMenu(Menu menu){
		// Inflate the menu items for use in the action bar
		MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.main_activity_actions, menu);
	    return super.onCreateOptionsMenu(menu);
	}

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle presses on the action bar items
        switch (item.getItemId()) {
            case R.id.action_search:
                //openSearch();
                return true;
            case R.id.action_settings:
                //openSettings();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }
    
    /**
     *  Called when the user clicks the Send button 
     */
    public void sendMessage(View view) {
        //Create the intent
    	Intent intent = new Intent(this, DisplayMessageActivity.class);
    	
    	//Obtain EditText, and add the message to the intent
    	EditText editText = (EditText) findViewById(R.id.edit_message);
    	String message = editText.getText().toString();
    	intent.putExtra(EXTRA_MESSAGE, message);
    	
    	//start the second activity
    	startActivity(intent);
    }
}
